/**
 * Created by zhangqingxi on 2017-03-31.
 */


/**
 * 加载表格
 *
 */
function  loadDataList() {

    $('#dataList').datagrid({
        url:modelPath+'findByParam.shtml',
        queryParams:{
            sort:'d.addTime',
            order:'desc'
        },
        // idField:'id',
        fitColumns:true,
        pagination:true,
        rownumbers:true,
        singleSelect:true,
        sortOrder:true,
        striped:true,
        fit:true,
        columns:[[
            {field:'id',width:10,checkbox:true},

            {field:'name',title:'预案名称',width:10,formatter:function (value,row,index) {
                return '<a href="javascript:void(0)" onclick="showDetails(\''+row.id+'\')" style="color: blue">'+value+'</a>'

            }},
            {field:'deptName',title:'所属单位',width:10},
            {field:'definitionName',title:'预案定义',width:10},
            {field:'hierarchyName',title:'预案层级',width:10},
            {field:'classificationName',title:'预案分类',width:10},
            {field:'typeName',title:'预案类型',width:10},
            {field:'deviceName',title:'装置场所',width:10},
            {field:'releaseDate',title:'发布时间',width:10},
            {field:'addUserName',title:'登记人',width:10},
            {field:'addDeptName',title:'登记部门',width:10},
            {field:'d.addTime',title:'登记时间',width:10,sortable:true,formatter:function (value,row,index) {
                return row.addTime;
            }}
        ]],
        toolbar: '#toolbar'

    });


}

$(function () {
    loadDataList();
    //高级查询
    initAdvancedSearch();

    //查询按钮事件
    initSearchClick();

    //重置参数
    initResetClick();


    //添加按钮事件
    $('#btn_emergency_plan_add').on('click',function () {

        openLayer("添加应急预案",modelPath+"add.shtml");

    });
    //编辑按钮事件
    $('#btn_emergency_plan_edit').on('click',function () {

        var checkedRows=$('#dataList').datagrid('getChecked');
        if(checkedRows.length === 0){
            layer.alert("选择需要修改的行！");
            return
        }
        var id=checkedRows[0].id;

        openLayer("编辑应急预案",modelPath+"edit.shtml?id="+id);


    });

    //删除按钮事件
    $('#btn_emergency_plan_delete').on('click',function () {

        var checkedRows=$('#dataList').datagrid('getChecked');
        if(checkedRows.length === 0){
            layer.alert("选择需要删除的行！");
            return
        }

        var id=checkedRows[0].id;
        initDeleteClick(modelPath,id);

    });





});
function showDetails(id) {

    openLayer("应急预案详情",modelPath+"details.shtml?id="+id);

}